package cn.ucai.GeoStack;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Map;

import org.w3c.dom.Text;

import edu.umn.cs.spatialHadoop.io.TextSerializerHelper;

public class GeoStackDataStore {
	private Object geom;

	@override
	public void write(DataOutput out ) throws IOException{
		out.writeLong(id);
		super.write(out);
		out .writeInt(tags.size());
		for (Map.Entry<String, String> tag : tags.entrySet())
			out.writeUTF(tag.getKey());
			out.writeUTF(tag.getValue());
	}
	
	@override
	public void readFields(DataInput in ) throws IOException{
		id=in.readLong();
		super.readFields(in);
		tags.clear();
		int size=in.readInt();
		while(size-- >0){
			String key=in.readUTF();
			String value=in.readUTF();
			tags.put(key,value);
		}
	}
	
	@override
	public void fromText(Text text ){
		id=TextSerializerHelper.consumeLong(text,SEPARATOR);
		this.geom=TextSerializerHelper.consumeGeometryJTS(text,SEPARATOR);
		tags.clear();
		TextSerializerHelper.consumeMap(text,tags);
	}
	
	@override
	public Text toText(Text text ) {
		TextSerializerHelper.serializeLong(id,text,SEPARATOR);
		TextSerializerHelper.serializeGeometry(text,geom,SEPARATOR);
		TextSerializerHelper.serializeMap(text,SEPARATOR);
		return text;
	}
}
